import Vue from "vue";
import Vuex from "vuex";

Vue.use(Vuex);

//实例化仓库
export default new Vuex.Store({
    state: {
        userInfo: '',//用户信息
        isLogin: false,//是否登录
    },
    getters: {
        userInfos(state) {
            return state.userInfo;//返回用户信息
        },
        isLogins(state) {
            return state.isLogin;
        }
    },
    mutations: {
        saveInfo(state, token) {
            if (token) {
                state.userInfo = token;//用户信息存储
                if (token.type != '1') {
                    state.isLogin = true;
                }
            }
        }
    },
    actions: {
        //保存用户信息
        changeStatus({ commit }, token) {
            commit('saveInfo', token);
        }
    }
});